﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;
using System.Globalization;
using System.Windows.Input;
using MJB.UI.ContentEditor.Document;

namespace MJB.UI.ContentEditor.Converters
{
    /// <summary>
    /// This converter class will convert KeyGesture objects to strings.
    /// </summary>
    public class KeyGestureToStringConverter : IValueConverter
    {
        #region IValueConverter Members

        /// <summary>
        /// Converts from a KeyGesture to a string.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            KeyGesture gesture = value as KeyGesture;
            if(gesture == null)
                return String.Empty;

            return gesture.GetDisplayStringForCulture(culture);
        }

        /// <summary>
        /// Cannopt convert back from a string to a key gesture.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new Exception("Cannot convert from a string to a KeyGesture!");
        }

        #endregion
    }

}
